package com.qianfeng.xinyihezi.xinyihezi.adapter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.qianfeng.xinyihezi.xinyihezi.R;
import com.qianfeng.xinyihezi.xinyihezi.model.DetailData;

import java.util.List;

/**
 * Created by Tcoy on 2016/11/14.
 */

public class RecyclerViewWholeAdapter extends RecyclerView.Adapter<RecyclerViewWholeAdapter.ViewHolder> {

    private List<DetailData> detailDataList;
    private LayoutInflater inflater;
    private Context context;
    private RecyclerViewDetailClassiftAdapter mAdapter;

    public RecyclerViewWholeAdapter(List<DetailData> detailDataList, Context context) {
        this.detailDataList = detailDataList;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        RecyclerViewWholeAdapter.ViewHolder viewHolder = null;
        View view = inflater.inflate(R.layout.classift_item_layout, null);
        viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tvTitle.setText(detailDataList.get(position).getName());
        mAdapter = new RecyclerViewDetailClassiftAdapter(detailDataList.get(position).getDetailSonCategoryList(), context);
        holder.recyclerViewGrid.setAdapter(mAdapter);
    }

    @Override
    public int getItemCount() {
        return detailDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tvTitle;
        private RecyclerView recyclerViewGrid;

        public ViewHolder(View itemView) {
            super(itemView);
            tvTitle = (TextView) itemView.findViewById(R.id.textViewClassiftTitle);
            recyclerViewGrid = (RecyclerView) itemView.findViewById(R.id.recyclerViewDetailClassGrid);
            recyclerViewGrid.setLayoutManager(new GridLayoutManager(context, 3, GridLayoutManager.VERTICAL, false));
        }
    }
}
